package com.monna.datebase;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * 创建DBHelper类，用于执行建库、建表操作
 * @author 廖梦青
 */
public class DBOpenHelper extends SQLiteOpenHelper {

    private static String dbName = "games2048.db";
    private static int dbVersion = 1;

    public DBOpenHelper(Context context) {
        super(context, dbName, null, dbVersion);
    }

    /**
     * 首次创建数据库时被调用，一般可以执行建库、建表操作
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table if not exists user(account varchar(255) primary key, " +
                "password varchar(255), name varchar(255))");
        db.execSQL("create table if not exists score(id integer primary key autoincrement," +
                " account varchar(255), height_score integer(11))");
    }

    /**
     * 当数据库的版本发生变化时，会自动执行
     * @param db
     * @param oldVersion
     * @param newVersion
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
